#define GPD0CON  	(*(volatile unsigned long *)0xE02000A0)
#define GPD0DAT		(*(volatile unsigned long *)0xE02000A4)
#define GPA0CON 	(*(volatile unsigned long *)0xE0200000)		
#define GPA1CON 	(*(volatile unsigned long *)0xE0200020)

#define ULCON2 			(*(volatile unsigned long *)0xE2900800)
#define UCON2			(*(volatile unsigned long *)0xE2900804)
#define UFCON2			(*(volatile unsigned long *)0xE2900808)
#define UMCON2			(*(volatile unsigned long *)0xE290080C)
#define UFSTAT2 		(*(volatile unsigned long *)0xE2900818)
#define UBRDIV2 		(*(volatile unsigned long *)0xE2900828)
#define UDIVSLOT2 		(*(volatile unsigned long *)0xE290082C)
#define UTXH2 			(*(volatile unsigned long *)0xE2900820)
#define URXH2 			(*(volatile unsigned long *)0xE2900824)
#define UTRSTAT2 		(*(volatile unsigned long *)0xE2900810)
#define UINTM2 			(*(volatile unsigned long *)0xE2900838)
#define UINTP2 			(*(volatile unsigned long *)0xE2900830)
#define UINTSP2 		(*(volatile unsigned long *)0xE2900834)



void uart_init()
{
    GPA0CON= 0x22222222;
    GPA1CON= 0x2222;//配置引脚为RX/TX功能
    UFCON2= 0x0;//使能FIFO
    UMCON2= 0x0;//无流控	
    ULCON2= 0x3;//数据位8,无校验,停止位1
    UCON2= 0x105; //时钟为PCLK，禁止中断，使能UART收 发
    UBRDIV2= 35;//设置波特率 				
    UDIVSLOT2= 0x1;
    UINTM2 = 0x0e; 
}

char getc()
{
	while(!(UTRSTAT2 & (1<<0)));
	return URXH2;
}

void putc(char c)
{
	while(!(UTRSTAT2 & (1<<2)));
	UTXH2 = c;
}

void irq_handler_uart2()
{
    //putc(getc()+1);
    putc('e');
    intc_clearvectaddr();
    UINTP2=0x0F;
    UINTSP2=0x0f;
}
